package com.HW;

import java.security.cert.TrustAnchor;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @ClassName : TKidsQueue
 * @Author : kele
 * @Date: 2023/10/25 21:46
 * @Description : 幼儿园排队
 */
public class TKidsQueue {

    public static void main(String[] args) {

        handle("1/N 2/Y 3/N 4/Y 5/Y");
    }

    public static void handle(String str) {

        String[] s = str.split(" ");

        HashMap<Boolean, ArrayList<Integer>> map = new HashMap<>();

        Boolean flag = true;

        ArrayList<Integer> list = new ArrayList<>();
        list.add(Integer.parseInt(s[0].split("/")[0]));
        map.put(true, list);

        for (int i = 1; i < s.length; i++) {

            String[] split = s[i].split("/");

            int num = Integer.parseInt(split[0]);
            String NY = split[1];
            if ("Y".equals(NY)) {
//                197204201265
                ArrayList<Integer> lst = map.getOrDefault(flag, new ArrayList<Integer>());
                lst.add(num);
                map.put(flag, lst);
            } else {
                flag = !flag;
                ArrayList<Integer> lst = map.getOrDefault(flag, new ArrayList<Integer>());
                lst.add(num);
                map.put(flag, lst);
            }
        }

        StringBuilder builder = new StringBuilder();


        List<Integer> trueArray = map.get(true);
        List<Integer> falseArray = map.get(false);

        trueArray.sort(Comparator.comparingInt(o -> o));
        falseArray.sort(Comparator.comparingInt(o -> o));

        List<String> collectTrue = trueArray.stream().map(Object::toString).collect(Collectors.toList());
        List<String> collectFalse = falseArray.stream().map(Object::toString).collect(Collectors.toList());
        System.out.println(String.join(" ",collectTrue));
        System.out.println(String.join(" ",collectFalse));

    }
}
